home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / _mulsi3.s < prev    next >
Text File  |  1993-10-20  |  1KB  |  49 lines

  1. | long integer multiplication routine
  2. |
  3. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  4. |
  5. |
  6. | Revision 1.1, kub 03-90
  7. | first version, replaces the appropriate routine from fixnum.s.
  8. | This one is longer, but normally faster because __umulsi3 is no longer
  9. | called for multiplication. Rather, the code is inlined here. See the
  10. | comments in _umulsi3.s
  11.  
  12.     .text
  13.     .even
  14.     .globl    __mulsi3, ___mulsi3, .lmul
  15.  
  16. .lmul:
  17. __mulsi3:
  18. ___mulsi3:
  19.     movel    d2,a0        | save registers
  20.     movel    d3,a1
  21.     movemw    sp@(4),d0-d3    | get the two longs. u = d0-d1, v = d2-d3
  22.     movew    d0,sp@-        | sign flag
  23.     bpl    0f        | is u negative ?
  24.     negw    d1        | yes, force it positive
  25.     negxw    d0
  26. 0:    tstw    d2        | is v negative ?
  27.     bpl    0f
  28.     negw    d3        | yes, force it positive ...
  29.     negxw    d2
  30.     notw    sp@        |  ... and modify flag word
  31. 0:
  32.     extl    d0        | u.h <> 0 ?
  33.     beq    1f
  34.     mulu    d3,d0        | r  = v.l * u.h
  35. 1:    tstw    d2        | v.h <> 0 ?
  36.     beq    2f
  37.     mulu    d1,d2        | r += v.h * u.l
  38.     addw    d2,d0
  39. 2:    swap    d0
  40.     clrw    d0
  41.     mulu    d3,d1        | r += v.l * u.l
  42.     addl    d1,d0
  43.     movel    a1,d3
  44.     movel    a0,d2
  45.     tstw    sp@+        | should the result be negated ?
  46.     bpl    3f        | no, just return
  47.     negl    d0        | else r = -r
  48. 3:    rts
  49.